#include "AlarmAction.h"
//#include "wxSMTP/wxsmtp.h"
#include "DBWrapper.h"

CAlarmAction::CAlarmAction(void)
{
}

CAlarmAction::~CAlarmAction(void)
{
}

int CAlarmAction::InitAlarm()
{
	CDBWrapper dbWrapper;

	wxString StdDataDir = wxStandardPaths::Get().GetDataDir();
	wxString DBName = StdDataDir + wxT("\\FusionSpy.db"); 

	dbWrapper.DBOpen( DBName, ADMINTABLE);
	if( dbWrapper.ActionSetQuery() > 0 ) {
		m_actionset = dbWrapper.getActionSet();
	} 
	return 1;
}
int CAlarmAction::PlayMusic()
{
	wxSound snd;
	wxString soundfile;

	if( m_actionset.SoundFile.IsNull() ) {
		wxString StdDataDir = wxStandardPaths::Get().GetDataDir();
		soundfile = StdDataDir + wxT("\\resources\\Alert.wav"); 
	} else {
		soundfile = m_actionset.SoundFile;
	}

	bool flag = snd.Create( soundfile );
	if (flag) {
		snd.Play(wxSOUND_ASYNC );
	}

	return 1;
}
int CAlarmAction::SendSMS(wxString content)
{

	return 1;
}
	
int CAlarmAction::SendMail(wxString content)
{
	if( m_actionset.SMTPPwd.IsNull() || m_actionset.SMTPSvr.IsNull() 
		|| m_actionset.SMTPUsr.IsNull() || m_actionset.MailTo.IsNull() ){
	} else {
/*
		wxSMTP *smtp = new wxSMTP(NULL);
		smtp->SetHost(m_actionset.SMTPSvr);
		wxEmailMessage *msg = new wxEmailMessage("Bug report",
												 "Your code really sucks.\n"
												 "Fix your code",
												 "fusionspy@sina.com.cn");
		msg->AddAlternative(content,wxT("text"),wxT("html"));
		msg->AddTo( m_actionset.MailTo );
		smtp->Send(msg);
*/
	}
	return 1;
}